package view

import (
	"Demo_Gin/model"
	"gitee.com/goddesszz/gocommon/viewdata"
	"github.com/gin-gonic/gin"
	"log"
)

func GetTreeData(ctx *gin.Context) {
	root := &model.Category{}
	categories := model.GetCategories()

	// 将Category转换为TreeData[int]
	nodes := make([]viewdata.TreeData[int], len(categories))
	for i := range categories {
		nodes[i] = &categories[i] // ✅ 取数组中每个元素的地址
	}

	treeData := viewdata.BuildTree[int](nodes, root)

	ctx.JSON(200, gin.H{
		"isOk": true,
		"data": treeData,
	})
}

func FlowCallback(ctx *gin.Context) {

	// 定义map接收JSON参数

	var reqData map[string]interface{}

	ctx.ShouldBindJSON(&reqData) // 绑定JSON数据到map

	log.Println(">>> 我接收到了Flow数据：", reqData)

	ctx.JSON(200, gin.H{
		"isOk": true,
		"msg":  "success",
	})

}
